package com.zjcloud.jwgl.domain;

import com.zjcloud.common.annotation.Excel;
import com.zjcloud.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 排课约束条件对象（重构版）
 * 与约束类型关联，支持更灵活的约束配置
 * 
 * @author zjcloud
 * @date 2024-01-01
 */
public class AcScheduleConstraint extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键ID */
    private Long id;

    /** 约束名称 */
    @Excel(name = "约束名称")
    @NotBlank(message = "约束名称不能为空")
    private String name;

    /** 约束类型ID */
    @Excel(name = "约束类型ID")
    @NotNull(message = "约束类型ID不能为空")
    private Long constraintTypeId;

    /** 权重(1-100) */
    @Excel(name = "权重")
    @NotNull(message = "权重不能为空")
    private Integer weight;

    /** 优先级(1-10，数字越大优先级越高) */
    @Excel(name = "优先级")
    private Integer priority;

    /** 描述 */
    @Excel(name = "描述")
    private String description;

    /** 学校ID */
    @Excel(name = "学校ID")
    private Long schoolId;

    /** 配置JSON（约束的具体参数配置） */
    private String configJson;

    /** 验证规则 */
    private String validationRule;

    /** 错误消息模板 */
    private String errorMessage;

    /** 是否启用：1-启用，0-禁用 */
    @Excel(name = "是否启用")
    private String enabled;

    /** 学期 */
    @Excel(name = "学期")
    private String semester;

    /** 排序号 */
    @Excel(name = "排序号")
    private Integer sortOrder;

    // 关联的约束类型信息（非数据库字段）
    private AcConstraintType constraintType;

    // 关联的约束参数列表（非数据库字段）
    private List<AcConstraintParameter> parameters;

    public void setId(Long id) 
    {
        this.id = id;
    }

    public Long getId() 
    {
        return id;
    }

    public void setName(String name) 
    {
        this.name = name;
    }

    public String getName() 
    {
        return name;
    }

    public void setConstraintTypeId(Long constraintTypeId) 
    {
        this.constraintTypeId = constraintTypeId;
    }

    public Long getConstraintTypeId() 
    {
        return constraintTypeId;
    }

    public void setWeight(Integer weight) 
    {
        this.weight = weight;
    }

    public Integer getWeight() 
    {
        return weight;
    }

    public void setPriority(Integer priority) 
    {
        this.priority = priority;
    }

    public Integer getPriority() 
    {
        return priority;
    }

    public void setDescription(String description) 
    {
        this.description = description;
    }

    public String getDescription() 
    {
        return description;
    }

    public void setSchoolId(Long schoolId) 
    {
        this.schoolId = schoolId;
    }

    public Long getSchoolId() 
    {
        return schoolId;
    }

    public void setConfigJson(String configJson) 
    {
        this.configJson = configJson;
    }

    public String getConfigJson() 
    {
        return configJson;
    }

    public void setValidationRule(String validationRule) 
    {
        this.validationRule = validationRule;
    }

    public String getValidationRule() 
    {
        return validationRule;
    }

    public void setErrorMessage(String errorMessage) 
    {
        this.errorMessage = errorMessage;
    }

    public String getErrorMessage() 
    {
        return errorMessage;
    }

    public void setEnabled(String enabled) 
    {
        this.enabled = enabled;
    }

    public String getEnabled() 
    {
        return enabled;
    }

    public void setSemester(String semester) 
    {
        this.semester = semester;
    }

    public String getSemester() 
    {
        return semester;
    }

    public void setSortOrder(Integer sortOrder) 
    {
        this.sortOrder = sortOrder;
    }

    public Integer getSortOrder() 
    {
        return sortOrder;
    }

    public void setConstraintType(AcConstraintType constraintType) 
    {
        this.constraintType = constraintType;
    }

    public AcConstraintType getConstraintType() 
    {
        return constraintType;
    }

    public void setParameters(List<AcConstraintParameter> parameters) 
    {
        this.parameters = parameters;
    }

    public List<AcConstraintParameter> getParameters() 
    {
        return parameters;
    }

    /**
     * 判断是否启用
     */
    public boolean checkEnabled() {
        return "1".equals(this.enabled);
    }

    /**
     * 判断是否为硬约束
     */
    public boolean isHardConstraint() {
        return constraintType != null && constraintType.isHardConstraint();
    }

    /**
     * 判断是否为软约束
     */
    public boolean isSoftConstraint() {
        return constraintType != null && constraintType.isSoftConstraint();
    }

    /**
     * 获取权重百分比
     */
    public double getWeightPercentage() {
        return weight != null ? weight / 100.0 : 0.0;
    }

    /**
     * 获取优先级描述
     */
    public String getPriorityDesc() {
        if (priority == null) {
            return "未设置";
        }
        if (priority >= 8) {
            return "极高";
        } else if (priority >= 6) {
            return "高";
        } else if (priority >= 4) {
            return "中";
        } else if (priority >= 2) {
            return "低";
        } else {
            return "极低";
        }
    }

    /**
     * 判断是否为高优先级
     */
    public boolean isHighPriority() {
        return priority != null && priority >= 6;
    }

    /**
     * 获取约束类型编码
     */
    public String getConstraintTypeCode() {
        return constraintType != null ? constraintType.getTypeCode() : null;
    }

    /**
     * 获取约束类型名称
     */
    public String getConstraintTypeName() {
        return constraintType != null ? constraintType.getTypeName() : null;
    }

    /** 约束类型（字符串类型，兼容旧接口） */
    private String type;

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("name", getName())
            .append("constraintTypeId", getConstraintTypeId())
            .append("weight", getWeight())
            .append("priority", getPriority())
            .append("description", getDescription())
            .append("schoolId", getSchoolId())
            .append("configJson", getConfigJson())
            .append("validationRule", getValidationRule())
            .append("errorMessage", getErrorMessage())
            .append("enabled", getEnabled())
            .append("semester", getSemester())
            .append("sortOrder", getSortOrder())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("remark", getRemark())
            .toString();
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}